<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>学生请假</title>
<meta name="description" content="">
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="${s.base}/phone/css/common.css">
<link rel="stylesheet" href="${s.base}/phone/css/font-awesome.css">
</head>
<body>
<input type="hidden" id="studentId"/>
<input type="hidden" id="id" value="${id}" />
<input type="hidden" id="personType" value="${personType}" />
<div class="tabPage" id="showList">
	<div class="course-content">

		<#list msgLeaveList as msgLeave>
			<a href="${s.base}/mobile/leave/${msgLeave.leaveId}?personType=${personType}&id=${id}">
		<div class="leave-list">
			<div class="dynamics-head">				
				<#if msgLeave.creatorHeadImage??>
					<img src="${msgLeave.creatorHeadImage}" />
					<#else>
						<img src="${s.base}/phone/images/wgz.jpg" />
				</#if>
				<div class="dynamics-right">
					<h3>${msgLeave.studentName}</h3><span class="notice-class"><#if msgLeave.creatorType=='1'>学生申请</#if><#if msgLeave.creatorType=='3'>家长申请</#if></span>
				  <span class="dynamics-class">
					  <!--老师-->
					  <#if personType=='2'>
						  <#if msgLeave.status=='1'>未查看</#if>
						  <#if msgLeave.status=='2'>已查看</#if>
						  <#if msgLeave.status=='3'>审核通过</#if>
						  <#if msgLeave.status=='4'>审核未通过</#if>
					  </#if>
					  <#if personType=='1' || personType=='3'>
						  <#if msgLeave.status=='1'>等待审核</#if>
						  <#if msgLeave.status=='2'>已查看</#if>
						  <#if msgLeave.status=='3'>审核通过</#if>
						  <#if msgLeave.status=='4'>审核未通过</#if>
					  </#if>
				  </span>
				</div>
				<time>${msgLeave.createTime?string('yyyy-MM-dd')}</time>
			</div>
			<span class="pass">
				<#if msgLeave.status=='3'><img src="${s.base}/phone/images/pass.png"/></#if>
				<#if msgLeave.status=='4'><img src="${s.base}/phone/images/no-pass.png"/></#if>

			</span>
		</div>
			</a>
		</#list>
	</div>
	<#if personType == "1" || personType == "3">
	<div class="dynamics-group">
		<input type="button" class="Editor-button" onclick="showContent('showAdd')" value="我要请假" />
	</div>
	</#if>
</div>
<div class="tabPage" id="showAdd" style="display: none">
	<div class="dynamics">
		<#if personType == "3">
			<div class="choose" onclick="showContent('showSelect')">请假人:<span id="showTitle"></span><i class="fa fa-angle-right"></i></div>
		</#if>
		<#if personType == "1">
			<div class="choose"  >请假人:<span>${msgStudent.studentName}</span></div>
		</#if>
		<div class="choose">开始时间:<span><input  id="startTime" type="date"/></span><i class="fa fa-angle-right"></i></div>
		<div class="choose">结束时间:<span><input id="endTime" type="date"/></span><i class="fa fa-angle-right"></i></div>
		<div class="Editor">
			<textarea rows="5" id="content" placeholder="请假事由"></textarea>
		</div>
	</div>

	<div class="dynamics-group">
		<input type="button" id="saveBtn" class="Editor-button" value="提交申请" />
	</div>

</div>
<div class="tabPage" id="showSelect" style="display: none">
	<div class="Seach-content">
		<ul>
			<#if personType == "3">
				<#list msgParentList as msgParents>
					<li><a href="javaScript:void(0)" onclick="showSelect('${msgParents.studentId}','${msgParents.studentName}')">${msgParents.gradeName}${msgParents.className}</a></li>
				</#list>

			</#if>
			</li>
		</ul>
	</div>
</div>
<script src="${s.base}/js/jquery-3.2.0.min.js"></script>

<script  type="application/javascript" src="${s.base}/js/layer/layer.js" ></script>
<script  type="application/javascript" src="${s.base}/js/layer/commont.js" ></script>
<script type="text/javascript">
    function showContent(id) {
        $(".tabPage").hide();
        $("#"+id).show();
    }
    function showSelect(id,name) {
        $("#showTitle").html(name);
        $("#studentId").val(id);
        showContent("showAdd");
    }
    $(document).ready(function () {
        $("#saveBtn").bind("click",function(){
            var id=$("#id").val();
            var startTime=$("#startTime").val();
            var endTime=$("#endTime").val();
            var content=$("#content").val();
            var studentId=$("#studentId").val();
            var personType=$("#personType").val();


            if(personType=='3'){
                if(studentId == "" || studentId==null){
                    offset("auto","请选择请假人！","温馨提示","确定");
                    return false;
                }
			}else{
                studentId=id;
			}
            if(startTime == "" || startTime==null){
                offset("auto","请选择开始时间！","温馨提示","确定");
                return false;
            }
            if(endTime == "" || endTime==null){
                offset("auto","请选择结束时间！","温馨提示","确定");
                return false;
            }
            if(content == "" || content==null){
                offset("auto","请输入请假事由！","温馨提示","确定");
                return false;
            }

            var url="${s.base}/mobile/leaveAdd";
            var params = {
                id: id,
                startTime: startTime,
                endTime: endTime,
                content: content,
                studentId: studentId,
                personType: personType
            };
            //调用了jquery.json 库
			/* var encoded = $.toJSON( request );
			 var jsonStr = encoded;*/
            $.ajax({
                url : url,
                type : 'POST',
                data : params,
                dataType : 'json',
                //contentType : 'application/json',
                success : function(data, status, xhr) {
                    if(1==data.returnInfo.state){
                        layer.open({
                            type: 1
                            ,title: "温馨提示"
                            ,offset: "auto" //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                            ,id: 'LAY_demoauto' //防止重复弹出
                            ,content: '<div style="padding: 20px 100px;">提交成功</div>'
                            ,btn: "确定"
                            ,btnAlign: 'c' //按钮居中
                            ,shade: 0 //不显示遮罩
                            ,yes: function(){
                                location.href="/mobile/leave?personType="+personType+"&id="+id;
                            }
                        });

                    }else{
                        offset("auto",data.returnInfo.errorMsg,"温馨提示","确定");
                    }

                },
                Error : function(xhr, error, exception) {
                    // handle the error.
                    offset("auto",exception.toString(),"温馨提示","确定");
                }
            });
        });
    })
</script>
</body>
</html>

